package org.bangumibuddy.security.config;

import org.bangumibuddy.config.property.JwtProperties;
import org.bangumibuddy.security.provider.BangumiAuthenticationProvider;
import org.bangumibuddy.security.service.BangumiUserDetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.authentication.AuthenticationProvider;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;


@Configuration
public class FilterConfig {
    @Autowired
    BangumiUserDetailService bangumiUserDetailService;

    @Autowired
    JwtProperties properties;

    @Bean
    public AuthenticationProvider bangumiAuthticationProvider(){
        BangumiAuthenticationProvider bangumiAuthenticationProvider = new BangumiAuthenticationProvider();
        bangumiAuthenticationProvider.setUserDetailsService(bangumiUserDetailService);
        bangumiAuthenticationProvider.setPasswordEncoder(passwordEncoder());
        bangumiAuthenticationProvider.setSECRET(properties.getSecret());

        return bangumiAuthenticationProvider;
    }

    public PasswordEncoder passwordEncoder(){
        return  new BCryptPasswordEncoder();
    }
}
